package com.al.study.record.sort;

/**
 * Created by yuxi on 2017/9/2.
 */
public class BubbleSort {
    public static void main(String[] args) {
        int[] arr = {3,3,3,3,3,3,4, 3};

        int[] insertSort = bubbleSort(arr);
        for (int i : insertSort) {
            System.out.print(i + "  ");
        }

    }

    /**
     * 冒泡排序
     *
     * @param arr
     * @return
     */
    private static int[] bubbleSort(int[] arr) {
        if (arr.length == 0) return null;
        for (int i = arr.length - 1; i > 0; i--) {
            for (int j = 0; j < i; j++) {
                if (arr[j] > arr[j + 1]) {
                    int temp = arr[j + 1];
                    arr[j + 1] = arr[j];
                    arr[j] = temp;
                }
            }
        }
        return arr;
    }
}
